﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using YAPL.Language.Core.Types;

namespace YAPL.Language.Ast.Transformation.Utils {
	public static class OperatorExpressionExtensions {
		private static readonly Dictionary<UnaryOperator, string> _unaryOperators =
	new Dictionary<UnaryOperator, string>();

		private static readonly Dictionary<BinaryOperator, string> _binaryOperators =
			new Dictionary<Ast.BinaryOperator, string>();

		 static OperatorExpressionExtensions() {
			_unaryOperators.Add(UnaryOperator.Plus, "UnaryPlus");
			_unaryOperators.Add(UnaryOperator.Minus, "UnaryMinus");
			_unaryOperators.Add(UnaryOperator.Increment, "Increment");
			_unaryOperators.Add(UnaryOperator.Decrement, "Decrement");
			_unaryOperators.Add(UnaryOperator.Not, "Not");

			_binaryOperators.Add(BinaryOperator.Plus, "Add");
			_binaryOperators.Add(BinaryOperator.Multiply, "Multiply");
			_binaryOperators.Add(BinaryOperator.Divide, "Divide");
			_binaryOperators.Add(BinaryOperator.Minus, "Subtract");
			_binaryOperators.Add(BinaryOperator.Mod, "Mod");
			_binaryOperators.Add(BinaryOperator.And, "And");
			_binaryOperators.Add(BinaryOperator.Or, "Or");
		}
		public static MethodInfo GetOperatorMethod(this BinaryExpression binaryExpression) {
			 return typeof(YAPLObject).GetMethod(_binaryOperators[binaryExpression.Operator], new[] { typeof(YAPLObject) });
		}
		public static MethodInfo GetOperatorMethod(this UnaryExpression unaryExpression) {
			return typeof(YAPLObject).GetMethod(_unaryOperators[unaryExpression.Operator], Type.EmptyTypes );
		}
	}
}
